package chabernac.android.wordbattle.paint.bogglemerge;

import android.graphics.Color;
import chabernac.android.wordbattle.WordRasterContext;
import chabernac.android.wordbattle.model.Word;
import chabernac.android.wordbattle.model.WordRaster;
import chabernac.android.wordbattle.paint.ClearAllDrawable;
import chabernac.android.wordbattle.paint.DrawableComposite;
import chabernac.android.wordbattle.paint.iDrawable;
import chabernac.android.wordbattle.paint.iDrawableFactory;
import chabernac.android.wordbattle.paint.bogglesimple.SelectedWordDrawable;

public class BoggleMergeDrawableFactory implements iDrawableFactory {

  private iDrawable myClearAllDraweble;
  private iDrawable myBackGroundDrawable;
  private iDrawable myWordRasterDrawable;
  
  @Override
  public iDrawable createGameDrawable( WordRaster aRaster ) {
    DrawableComposite theComposite = new DrawableComposite();
    
    theComposite.addDrawable( createClearAllDrawable() );
//    theComposite.addDrawable( createBackGroundDrawable() );
    theComposite.addDrawable( createSelectedLettersDrawable( new Word(WordRasterContext.getInstance().getMediator().getWordRaster().getSelectedLetters() )));
    theComposite.addDrawable( createWordRasterDrawable( aRaster ));
    //theComposite.addDrawable( createSelectedWordsDrawable(aRaster) );
    
    return theComposite;

  }

  private iDrawable createClearAllDrawable() {
    if(myClearAllDraweble == null){
      myClearAllDraweble = new ClearAllDrawable( Color.WHITE );
    }
    return myClearAllDraweble;
  }
  
  public iDrawable createBackGroundDrawable() {
    if(myBackGroundDrawable == null){
      myBackGroundDrawable = new BoggleMergeBackGroundDrawable( );
    }
    return myBackGroundDrawable;
  }

  private iDrawable createSelectedLettersDrawable( Word aWord ) {
   return new SelectedWordDrawable(aWord);
  }

  private iDrawable createWordRasterDrawable( WordRaster aRaster ) {
    if(myWordRasterDrawable == null) {
      myWordRasterDrawable = new MergeBoggleWordRasterDrawable( aRaster );
    }
    return myWordRasterDrawable;
  }

}
